<template>
  <div style="margin-left:10px">
    <div>
      <div style="margin-top:10px">
        <el-form inline>
          <el-form-item label="姓名">
            <el-input style="max-width:200px"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input style="max-width:200px"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <el-table border :data="tableData" style="width: 50%">
        <el-table-column prop="id" label="id"> </el-table-column>
        <el-table-column prop="userName" label="姓名" width="180">
        </el-table-column>
        <el-table-column prop="passWord" label="密码"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="delRow(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    新增
    <el-input v-model="userName" style="width:200px"></el-input>
    <el-input v-model="passWord" style="width:200px"></el-input>
    <el-button @click="getList">刷新</el-button>
    <el-button @click="addLogin">提交</el-button>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "XXX系统",
  data() {
    return {
      tableData: [],
      userName: "",
      passWord: ""
    };
  },
  computed: {},
  created() {
    this.getList();
    

    
  },
  methods: {
    getList() {
      axios.get("http://127.0.0.1:8081/info/getInfo").then((res) => {
        if (res.data.flag) {
          this.tableData = res.data.data;
        } else {
          this.$message.error(res.data.message);
        }
      });
    },
    addLogin() {
      axios
        .post("http://127.0.0.1:8081/info/add", {
          userName: this.userName,
          passWord: this.passWord
        })
        .then((res) => {
          if (res.data.flag) {
              this.getList()
          }
        });
    },
    delRow(row) {
      axios.post("http://127.0.0.1:8081/info/delLogin/?id="+row.id).then((res) => {
        if (res.data.flag) {
          this.getList()
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
